<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
</head>
<body>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
<!-- 新 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/bootstrap-theme.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/default.css">

<!-- Custom styles for this template -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/dashboard.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/adminnav.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/bootstrap/css/style.css">

<!-- jQuery文件。务必在bootstrap.min.js 之前引入 -->
<script src="${pageContext.request.contextPath}/static/js/jquery-1.11.3.js"></script>
<script src="${pageContext.request.contextPath}/static/js/functions.js"></script>

<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="${pageContext.request.contextPath}/static/css/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/static/css/bootstrap/js/prettify.min.js"></script>
<script src="${pageContext.request.contextPath}/static/css/bootstrap/js/multiselect.min.js"></script>

<script type="text/javascript">
    $(document).ready(
        function selGoodsBut(formName, cbName) {
            if ($("#selAllGoods").is(":checked"))
                selectAll(formName, cbName);
            else
                unSelectAll(formName, cbName);
        },

        function check() {
            return confirm("确实要删除选中的商品吗？");
        }
</script>

<c:import url="../common/adminTopNav.jsp"/>

<div class="container-fluid">
    <div class="row">
        <div class="col-sm-3 col-md-2 sidebar">

            <c:import url="../common/adminLeftNav.jsp"/>

        </div>
        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <%--content--%>

            <div class="row">
                <div class="col-md-10">
                    <form class="form-inline" role="form" id="searchForm" method="post"
                          action="${pageContext.request.contextPath}/product/productList">
                        <div class="form-group">
                            <label for="cateId"> 商品类别</label>
                            <select class="form-control input-sm" name="cid" id="cateId">
                                <option value="">---所有类别---</option>
                                <c:forEach items="${categoryList}" var="category">
                                    <option value="${category.cid}"
                                            <c:if test="${conditions.cid==category.cid}">selected</c:if>>${category.name}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <div class="form-group">
                            <label for="goodsName"> 商品名称</label>
                            <input class="form-control input-sm" name="keyword" id="goodsName"
                                   value="${conditions.keyword}"
                                   placeholder="商品名称"/>
                        </div>
                        <div class="form-group">
                            <label for="price"> 价格 </label>
                            <input class="form-control input-sm" name="startPrice" id="startPrice"
                                   value="${conditions.startPrice}"
                                   type="number" placeholder="起始价格" minlength="0"/>-
                            <input class="form-control input-sm" name="endPrice" id="endPrice"
                                   value="${conditions.endPrice}" type="number"
                                   placeholder="终止价格" minlength="0"/>
                        </div>
                        <button class="btn btn-primary btn-sm" type="submit">搜索</button>
                    </form>
                </div>
                <div class="col-md-2">
                    <div class="dropdown" id="dropdown">
                        <button class="btn btn-default dropdown-toggle btn-sm" type="button" id="dropdownMenu1"
                                data-toggle="dropdown" aria-haspopup="true" aria-expanded="true" onclick="dropdown()">
                            排序
                            <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
                            <li>
                                <a href="${pageContext.request.contextPath}/product/productList?cid=${conditions.cid}&keyword=${conditions.keyword}&startPrice=${conditions.startPrice}&endPrice=${conditions.endPrice}&sort=1">按价格从低到高</a>
                            </li>
                            <li>
                                <a href="${pageContext.request.contextPath}/product/productList?cid=${conditions.cid}&keyword=${conditions.keyword}&startPrice=${conditions.startPrice}&endPrice=${conditions.endPrice}&sort=2">按价格从高到低</a>
                            </li>
                            <li class="divider">
                            </li>
                            <li>
                                <a href="${pageContext.request.contextPath}/product/productList?cid=${conditions.cid}&keyword=${conditions.keyword}&startPrice=${conditions.startPrice}&endPrice=${conditions.endPrice}&sort=3">按销量从高到低</a>
                            </li>
                            <li>
                                <a href="${pageContext.request.contextPath}/product/productList?cid=${conditions.cid}&keyword=${conditions.keyword}&startPrice=${conditions.startPrice}&endPrice=${conditions.endPrice}&sort=4">按销量从低到高</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>


            <h2 class="sub-header">商品信息列表</h2>

            <div class="table-responsive ">
                <form name="goodsForm" method="post" action="${pageContext.request.contextPath}/product/delBatchByPids"
                      onsubmit="return check()">
                    <button class="btn btn-primary" type="submit">批量删除</button>
                    <table class="table table-striped">
                        <thead>
                        <tr>
                            <th><input type="checkbox" id="selAllGoods"
                                       onchange="selGoodsBut('goodsForm', 'goodsIds')"/> 全选
                            </th>
                            <th>#</th>
                            <th>商品名称</th>
                            <th>商品图片</th>
                            <th>商品总库存</th>
                            <th>商品总销量</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${products}" var="product" varStatus="status">
                            <tr>
                                <td><input type="checkbox" name="pids" value="${product.pid}"/></td>
                                <td>${status.count}</td>
                                <td>${product.name}</td>
                                <td><img src="${product.url}" width="50" height="50"></td>
                                <td>${empty product.store?0:product.store}</td>
                                <td>${empty product.sale?0:product.sale}</td>
                                <td>
                                    <a class="btn btn-primary"
                                       href="${pageContext.request.contextPath}/product/toUpdateStore?pid=${product.pid}">管理商品库存</a>
                                </td>
                            </tr>
                        </c:forEach>
                        </tbody>
                    </table>
                </form>
            </div>
        </div>
    </div>
</div>

<c:import url="../common/adminFooter.jsp"/>

</body>
</html>